﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using HZ.Supervise.Model.Query;

namespace HZ.Supervise.Web.Hospital
{
    public partial class ContractUpdate2 : BasePage
    {
        HZ.Supervise.IBLL.IExecuteContext i = HZ.Supervise.BLLFactory.ExecuteContext();
        public string orderID = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request["orderID"] != null)
                {
                    orderID = Request["orderID"].ToString();
                    BindSort();
                    SetBind();
                }
            }
        }
        //绑定分类名称
        private void BindSort()
        {
            ddlSortName.DataSource = i.GetSortNameDXSB();
            ddlSortName.DataTextField = "SortName";
            ddlSortName.DataValueField = "SortName";
            ddlSortName.DataBind();
            ddlSortName.Items.Insert(0, new ListItem("全部", ""));
        }
        private void SetBind()
        {
            int totalCount = 0;
            DataTable dt = i.GetOrderDetailDXSB(GetQurey(), this.AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalCount);
            AspNetPager1.RecordCount = totalCount;
            gvwProduceCatalog.PageSize = AspNetPager1.PageSize;
            gvwProduceCatalog.DataSource = dt;
            gvwProduceCatalog.DataBind();
        }
        private QGoodsDXSB GetQurey()
        {
            QGoodsDXSB qd = new QGoodsDXSB();
            qd.GoodsID = txtGoodsid.Text.Trim();
            qd.ProductName = txtGoodsName.Text.Trim();
            qd.RegCode = txtRegCode.Text.Trim();
            qd.CompanyName_SC = txtProduceCompany_SC.Text.Trim();
            qd.Outlookc = txtOutLook.Text.Trim();
            qd.ProductionArea = txtProductionArea.Text.Trim();
            qd.SaleServices = txtSaleServices.Text.Trim();
            qd.SortName = ddlSortName.SelectedValue;
            qd.Append = string.Format("OrderID='{0}' ", Request["orderID"]);
            qd.SortFields = "AddTime desc";
            return qd;
        }
        private string str()
        {
            string s = string.Format(" and OrderID='{0}' ", Request["orderID"]);
            if (!string.IsNullOrEmpty(txtGoodsid.Text.Trim()))
            {
                s += string.Format(" and a.GoodsID='{0}' ", txtGoodsid.Text.Trim());
            }
            if (!string.IsNullOrEmpty(txtGoodsName.Text.Trim()))
            {
                s += string.Format(" and CHARINDEX('{0}',ProductName)>0 ", txtGoodsName.Text.Trim());
            }
            if (!string.IsNullOrEmpty(txtRegCode.Text.Trim()))
            {
                s += string.Format(" and CHARINDEX('{0}',RegCode)>0 ", txtRegCode.Text.Trim());
            }
            if (!string.IsNullOrEmpty(txtProduceCompany_SC.Text.Trim()))
            {
                s += string.Format(" and CHARINDEX('{0}',CompanyName_SC)>0 ", txtProduceCompany_SC.Text.Trim());
            }
            if (!string.IsNullOrEmpty(txtOutLook.Text.Trim()))
            {
                s += string.Format(" and CHARINDEX('{0}',Outlookc)>0 ", txtOutLook.Text.Trim());
            }
            if (!string.IsNullOrEmpty(txtProductionArea.Text.Trim()))
            {
                s += string.Format(" and CHARINDEX('{0}',ProductionArea)>0 ", txtProductionArea.Text.Trim());
            }
            if (!string.IsNullOrEmpty(txtSaleServices.Text.Trim()))
            {
                s += string.Format(" and CHARINDEX('{0}',SaleServices)>0 ", txtSaleServices.Text.Trim());
            }
            if (!string.IsNullOrEmpty(ddlSortName.SelectedValue))
            {
                s += string.Format(" and SortName='{0}' ", ddlSortName.SelectedValue);
            }
            return s;
        }
        protected void btnExport_Click(object sender, EventArgs e)
        {
            int totalCount = 0;
            DataTable dt = i.GetOrderDetailDXSB(GetQurey(), 1, 0, out totalCount);
            if (dt.Rows.Count > 0)
            {
                ExportFile.Instance.ExportData(dt, gvwProduceCatalog, this);
            }
            else
            {
                HZ.Web.WebUtil.Alert("没有需导出的数据", this.Page);
            }
        }
        protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
        {
            SetBind();
        }
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
        }
    }
}